#include    <stdio.h>
 #include<unistd.h>
 #include    <signal.h>
 #define INPUTLEN    100
void inthandler();  
int main()
{
struct sigaction newhandler;    
sigset_t blocked;   //被阻塞的信号集
char x[INPUTLEN];
newhandler.sa_handler = inthandler; 
newhandler.sa_flags = SA_RESTART|SA_NODEFER
    |SA_RESETHAND;  
sigemptyset(&blocked);  //清空信号处理掩码
sigaddset(&blocked, SIGQUIT);   
newhandler.sa_mask = blocked;   
if (sigaction(SIGINT, &newhandler, NULL) == -1)
    perror("sigaction");
else
    while (1) {
        fgets(x, INPUTLEN, stdin);    //fgets()会在数据的最后附加"\0"
        printf("input: %s", x);
    }
return 0;
}
void inthandler(int s)
{
printf("Called with signal %d\n", s);
sleep(s * 4);
printf("done handling signal %d\n", s);
}
